#include <stdio.h>

int josephus(int n, int k) {
    int survivor = 0; // J(1, k) = 0
    for (int i = 2; i <= n; i++) {
        survivor = (survivor + k) % i;
    }
    return survivor;
}

int main() {
    int n, k;
    printf("请输入学徒人数n: ");
    scanf("%d", &n);
    printf("请输入每次淘汰的间隔k: ");
    scanf("%d", &k);

    int luckyApprentice = josephus(n, k);
    printf("幸运学徒的编号是: %d\n", luckyApprentice);
    return 0;
}
